module enum_method;

typedef enum { fsby4, hb1, mixer, polyphase1, polyphase2, channel_filter }
cdma_ddc_lineup;

// example declartion of assigning values in binary
//enum integer {IDLE, XX='x, S1='b01, S2='b10} state, next;

cdma_ddc_lineup c0;
cdma_ddc_lineup c1;
integer i;

// name() gives the string representation of the value
initial
begin

   // the elements in the enum as defined
   //c0 = c0.first ; //This is not required, as the left most value is implicitly assigned
   for ( i=0; i<=c0.last; i++)
   begin
      $display("Element %d : %s", i+1, cdma_ddc_lineup'(c0+i) );
   end

   //c0 = c0.first;
   c0 = fsby4 ;
   $display("The first element is %s", c0.name);
   c0 = c0.next();
   $display("The second element is %s", c0.name());

   c0 = c0.next;
   $display("The third element is %s", c0.name);
   c1 = c0.prev();
   c1 = cdma_ddc_lineup'(c1+1); // type casting 
   $display("The third element is %s", c1.name);
   i = c1 ;  //assigned to integer value
   $display("The third element is %s", cdma_ddc_lineup'(i) );

   c0 = c0.last;
   $display("The last element is %s", c0.name);
   c0 = c0.prev();
   $display("The second last element is %s", c0.name);

   // access the index beyond the last element results in EMPTY string
   // note that the index is incremented and NOT accessed using next() fn.
   c1 = cdma_ddc_lineup'(c0.next+1);
   $display("\nTry to access an element after the last element");
   $display("The non-existing element after the defined last element is %s", c1.name);

   // access the index beyond the first element results in EMPTY string
   // note that the index is decremented and NOT accessed using prev() fn.
   c1 = c1.first;
   c1 = cdma_ddc_lineup'((c1.first) -1); 
   $display("Try to access an element before the first element");
   $display("The non-existing element before the defined first element is %s", c1.name);

   // access the index beyond the last element using next() results in the FIRST element
   c1 = (c0.next);
   c1 = c1.next;
   $display("\nThe element after the defined last element (using next fn) is %s", c1.name);

   // access the index before the first element using prev() results in the LAST element
   c1 = c1.first;
   c1 = c1.prev; 
   $display("The element before the defined first element (using prev fn) is %s", c1.name);
   $display(" Note that it acts as circular buffer, if accessed using next and prev funtions");
end

endmodule
